<template>
  <tab-bar>
    <div
      slot="main"
      v-infinite-scroll="loadMore"
      infinite-scroll-disabled="disabledScroll"
      infinite-scroll-distance="10"
      infinite-scroll-immediate-check="false"
      class="scroll-view">
      <div class="index-banner" :style="`height:${bannerHt}px`">
        <mt-swipe :auto="5000">
          <mt-swipe-item v-for="(val, key) in banners" :key="key">
            <img :src="$file + val.caad03" alt="">
          </mt-swipe-item>
        </mt-swipe>
      </div>
      <div class="rollNotice">
        <div class="left">
          <img src="../home/zixun.png" alt="">
          <span>动态</span>
        </div>
        <yd-rollnotice :autoplay="3000">
          <yd-rollnotice-item v-for="(val, key) in rollList" :key="key">
            <router-link :to="`/corp-home/news?canc11=${val.canc11 || ''}&cand01=${val.cand01 || ''}`" class="roll-notice-item">{{val.cand03}}</router-link>
          </yd-rollnotice-item>
        </yd-rollnotice>
      </div>
      <router-link to="/corp-query">
        <img src="./1.png" alt="综合查询" style="width: 100%;">
      </router-link>
      <mt-navbar v-model="selected">
        <mt-tab-item id="XWDT">新闻动态</mt-tab-item>
        <mt-tab-item id="XYXX">行业消息</mt-tab-item>
        <mt-tab-item id="TGGG">通知公告</mt-tab-item>
      </mt-navbar>
      <div class="news-list">
        <router-link :to="`/corp-home/news?canc11=${val.canc11 || ''}&cand01=${val.cand01 || ''}`" class="item" v-for="(val, key) in list" :key="key">
          <span class="title">{{val.cand03}}</span>
          <div class="content">
            <span>{{$dateFormat(val.cand07).format('YYYY-MM-DD')}}</span>
            <span>{{val.cand13}} 阅读</span>
          </div>
        </router-link>
      </div>
      <loading-text v-if="loading"></loading-text>
      <finish-text v-if="noMore"></finish-text>
      <empty v-if="empty"></empty>
      <yd-backtop></yd-backtop>
    </div>
    <transition name="router" mode="out-in">
      <router-view class="fixed-router"></router-view>
    </transition>
  </tab-bar>
</template>
<script>
  import TabBar from '../../layouts/tab-bar/index.vue'
  import LoadingText from '../../components/loading-text/loading-text.vue'
  import FinishText from '../../components/finish-text/finish-text.vue'
  import {infinite} from '../../common/js/mixin'
  import Empty from '../../components/empty/empty'

  export default {
    components: {
      Empty,
      FinishText,
      LoadingText,
      TabBar},
    computed: {
      ...infinite
    },
    data() {
      return {
        bannerHt: 0,
        selected: 'XWDT',
        rollList: [],
        banners: [],
        /* 以下五个参数为上拉加载页面必需的参数 */
        loading: true,
        page: 1,
        size: 10,
        total: 0,
        list: []
        /* 以上五个参数为上拉加载页面必需的参数 */
      }
    },
    methods: {
      loadMore() {
        if (this.page === 1) this.list = []
        this.$post('/sapi/news/get/article/list', {
          canc11: this.selected,
          page: this.page,
          rows: this.size
        }, loading => {
          this.loading = loading
        }).then(res => {
          if (this.page === 1 && this.selected === 'XWDT') {
            this.rollList = res.data.articleList
          }
          this.list = this.list.concat(res.data.articleList)
          this.total = res.data.articleListPageBean.totalCount
          this.page++
        })
      },
      getBanners() {
        this.$post('/sapi/advert/get/ad/web/list', {
          indent: 'zwwgw_banner'
        }).then(res => {
          this.banners = res.data.adWebList
        })
      }
    },
    created() {
      this.bannerHt = document.body.clientWidth * 8 / 15
      this.loadMore()
      this.getBanners()
      this.$watch('selected', () => {
        setTimeout(() => {
          this.page = 1
          this.loadMore()
        }, 20)
      })
    }
  }
</script>
<style lang="scss" scoped>
  @import "../../common/style/variable";
  .index-banner{
    img{
      width: 100%;
    }
  }
  .rollNotice{
    display: flex;
    background: #fff;
    padding: .1rem .1rem;
    margin: 0 0 4px 0;
    .roll-notice-item{
      display: inline-block;
      width: 100%;
      @include ellipsis;
    }
    .left{
      white-space: nowrap;
      padding: 0 .1rem;
      align-items: center;
      display: flex;
      img{
        width: .85rem;
      }
      span{
        line-height: .33rem;
        margin: 0 .1rem;
        display: inline-block;
        padding: .05rem .1rem;
        border-radius: .15rem;
        background: #eb6c00;
        color: #fff;
      }
    }
  }
  .news-list{
    background: #fff;
    .item{
      display: block;
      padding: .2rem .2rem;
      border-bottom: 1px solid #ededed;
      @include active;
      &:first-child{
        border-top: 1px solid #ededed;
      }
      .title{
        font-size: .3rem;
        display: inline-block;
        width: 100%;
        @include ellipsis;
        padding: 0 0 .1rem 0;
      }
      .content{
        display: flex;
        align-items: center;
        justify-content: space-between;
        color: #666;
        .xf-liulan{
          font-size: .26rem;
        }
      }
    }
  }
</style>
